package com.hp.attendance.serlvet.oneself;



import com.hp.attendance.entity.Department;
import com.hp.attendance.entity.Employee;
import com.hp.attendance.service.OneselfService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/oneselfOverAdd")
public class OneselfOverPreAddServlet extends HttpServlet {
    private OneselfService oneselfService =new OneselfService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            Employee emp = (Employee) req.getSession().getAttribute("emp");
            Department department = oneselfService.getDepartmentByDN(emp.getDepartment_number());
            req.setAttribute("employee",emp);
            req.setAttribute("department",department);
            List<Employee> eList = new ArrayList<>();
            List<Department> depList = new ArrayList<>();
            eList.add(emp);
            depList.add(department);
            req.setAttribute("dList",depList);
            req.setAttribute("eList",eList);
            req.getRequestDispatcher("/pages/onself_overtime_add.jsp").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
